/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package analizador;

/**
 *
 * @author ANIBAL
 */
public class ValidarVariable extends AnalizadorLexico {

    private String cadenaVariable;

    public ValidarVariable() {
    }

    public Token validarvariable(String cadena) {
        cadenaVariable = cadena;
        Token token = Token.TokenError;
        int aux = 0;
        char[] arregloCar = cadenaVariable.toCharArray();//convierto en un arreglo de caracteres
        for (int x = 0; x < arregloCar.length; x++) {

            switch (aux) {
                case 0:
                    if (Character.isLetter(arregloCar[x]) || arregloCar[x] == ('_')) {//si inicia con "_"
                        aux = 1;
                        token = Token.TokenVariable;
                    } else {
                        token = Token.TokenError;
                        return token;
                    }
                    break;
                case 1:
                    if (Character.isLetter(arregloCar[x]) || Character.isDigit(arregloCar[x]) || arregloCar[x] == ('_')) {
                        token = Token.TokenVariable;
                        aux = 1;
                    } else {
                        token = Token.TokenError;
                        return token;
                    }
                    break;
            }
        }
        return token;
    }
}
